package org.darkbits.cyklon.machine;

import java.lang.reflect.Method;

public class MethodInput extends AbstractOrderedInput {
	String name;
	int order;
	Method method;
	Machine owner;
	Class type;
	
	public void write(Object data) throws InputException {
		Object args[] = new Object[1];
		args[0] = data;
		try {
			method.invoke(owner, args);
		} catch (Exception e) {
			throw new InputException();
		}
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getOrder() {
		return order;
	}

	public void setOrder(int order) {
		this.order = order;
	}

	public Machine getOwner() {
		return owner;
	}

	public Class getType() {
		return type;
	}

	public MethodInput(Machine owner, String name, int order, Method method) {
		super();
		this.name = name;
		this.order = order;
		this.method = method;
		this.owner = owner;
		this.type = method.getParameterTypes()[0];
	}

	
}
